package date.Exa2;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.ChronoUnit;

/**
 * 当地日期Api学习
 */
public class LocalDateStudy {
    public static void main(String[] args) {

        //获取当地当前日期
        LocalDate today = LocalDate.now();
        System.out.println("获取当地当前日期,今天是："+today);

        //获取指定日期对象
        LocalDate alozosBirthday = LocalDate.of(1903,6,14);
        System.out.println("获取指定日期对象: "+alozosBirthday);

        //向后移动指定天数
        LocalDate programmersDay = LocalDate.of(2018,1,1).plusDays(255);
        System.out.println("向后移动指定天数: "+programmersDay);

        //根据枚举值创建本地日期对象
        LocalDate independenceDay = LocalDate.of(2018, Month.JULY,4);
        LocalDate christmas = LocalDate.of(2018,Month.DECEMBER,25);

        //计算两个日期相隔的天数
        System.out.println("计算两个日期相隔的天数: "+independenceDay.until(christmas));
        System.out.println("计算两个日期相隔的天数: "+independenceDay.until(christmas, ChronoUnit.DAYS));

        //向后/向前移动指定天数
        System.out.println("向后/向前移动指定天数:");
        System.out.println(LocalDate.of(2016,1,31).plusMonths(1));
        System.out.println(LocalDate.of(2016,1,31).minusMonths(1));

        //获取指定日期是星期几
        DayOfWeek week = LocalDate.of(1900,1,1).getDayOfWeek();
        System.out.println("获取指定日期是星期几 : "+week);
        System.out.println("获取指定日期是星期几 : "+week.getValue());
        System.out.println("获取指定日期后面几天的星期几 : "+week.plus(2));
        System.out.println("获取指定日期后面几天的星期几 : "+week.plus(2).getValue());

    }
}
